package com.neusoft.neuiotms.dcam.fixed.converter.spareconsume;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcam.fixed.dto.spareconsume.SpareConsumeApproveDTO;
import com.neusoft.neuiotms.dcam.fixed.model.spareconsume.SpareConsumeApprove;
import com.neusoft.neuiotms.dcam.fixed.repository.spareConsume.SpareConsumeApproveRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SpareConsumeApproveConver extends AbstractConverter<SpareConsumeApprove, SpareConsumeApproveDTO> {

    @Autowired
    private SpareConsumeApproveRepository spareConsumeApproveRepository;

    @Override
    public SpareConsumeApprove toModel(SpareConsumeApproveDTO dto) {
        SpareConsumeApprove model;
        if (dto.isNew()) {
            model = new SpareConsumeApprove();
        } else {
            model = this.spareConsumeApproveRepository.getOne(dto.getId());
        }

        model.setApprovalComments(dto.getApprovalComments());
        model.setTaskId(dto.getTaskId());
        model.setWorkNum(dto.getWorkNum());
        model.setOperatorCode(dto.getOperatorCode());
        model.setOperatorName(dto.getOperatorName());
        model.setWhetherAgree(dto.getWhetherAgree());
        return model;
    }

    @Override
    public SpareConsumeApproveDTO toDTO(SpareConsumeApprove model, boolean forListView) {
        final SpareConsumeApproveDTO dto = new SpareConsumeApproveDTO();
        dto.setId(model.getId());
        dto.setApprovalComments(model.getApprovalComments());
        dto.setTaskId(model.getTaskId());
        dto.setWorkNum(model.getWorkNum());
        dto.setOperatorCode(model.getOperatorCode());
        dto.setOperatorName(model.getOperatorName());
        dto.setWhetherAgree(model.getWhetherAgree());
        return dto;
    }
}
